
clc; clear; close all;

% 参数设置
c = 1.7;    % TO-GM 中的耦合强度
d = 1.8;    % CO-GM 中的耦合强度

% 取值范围
phi3_min = -4;  phi3_max = 4;   % TO-GM
x3_min   = -5;  x3_max   = 5;

phi4_min = 0;  phi4_max = 15;  % CO-GM
x4_min   = -5;   x4_max   = 5;

% 网格密度
N = 501;   % 越大曲线越平滑, 但绘图越慢

% ===奇/偶分支和公共方程的交点表是真正的固定点===

%% TO-GM 固定点方程绘图
subplot(1,2,1);
hold on; grid on; box on;

[PHI3,X3] = meshgrid(linspace(phi3_min,phi3_max,N), linspace(x3_min,x3_max,N));

% 定义三条方程:
% odd:  F1_odd = c sin(phi3)*x3 - x3 - 1
F1_odd  = c.*sin(PHI3).*X3 - X3 - 1;
% even: F1_even= c sin(phi3)*x3 - x3 + 1
F1_even = c.*sin(PHI3).*X3 - X3 + 1;
% F2    = -0.14 phi3 + 0.12 phi3|phi3| - 0.02 phi3^3 + 0.1 x3
F2      = -0.14.*PHI3 + 0.12.*PHI3.*abs(PHI3) - 0.02.*(PHI3.^3) + 0.1.*X3;

% contour绘制: 在 (PHI3, X3) 平面上找 F=0 的曲线
contour(PHI3, X3, F1_odd,  [0 0], 'r','LineWidth',1.2);
contour(PHI3, X3, F1_even, [0 0], 'b','LineWidth',1.2);
contour(PHI3, X3, F2,      [0 0], 'g','LineWidth',1.2);

xlabel('\phi_3'); ylabel('x_3');
title('(a) TO-GM 固定点方程');
legend({'F1 odd=0','F1 even=0','F2=0'}, 'Location','best');

%% CO-GM 固定点方程绘图
subplot(1,2,2);
hold on; grid on; box on;

[PHI4,X4] = meshgrid(linspace(phi4_min,phi4_max,N), linspace(x4_min,x4_max,N));

% odd:  L1_odd  = -0.8 + d cos(phi4)*x4 - x4
L1_odd  = -0.8 + d.*cos(PHI4).*X4 - X4;
% even: L1_even =  0.8 + d cos(phi4)*x4 - x4
L1_even =  0.8 + d.*cos(PHI4).*X4 - X4;
% L2    = 0.1 tanh(phi4^3) - 0.01 phi4 + 0.1 x4
L2      = 0.1.*tanh(PHI4.^3) - 0.01.*PHI4 + 0.1.*X4;

contour(PHI4, X4, L1_odd,  [0 0], 'r','LineWidth',1.2);
contour(PHI4, X4, L1_even, [0 0], 'b','LineWidth',1.2);
contour(PHI4, X4, L2,      [0 0], 'g','LineWidth',1.2);

xlabel('\phi_4'); ylabel('x_4');
title('(b) CO-GM 固定点方程');
legend({'L1 odd=0','L1 even=0','L2=0'}, 'Location','best');

% 设置整体标题(中文示例)
sgtitle('固定点方程曲线');
